using Baci.Net.ToolKit.ArcGISProGeoprocessor.Models;
using Baci.Net.ToolKit.ArcGISProGeoprocessor.Models.Attributes;
using Baci.Net.ToolKit.ArcGISProGeoprocessor.Models.Attributes.DomainAttributes;
using Baci.Net.ToolKit.ArcGISProGeoprocessor.Models.Enums;
using System.Collections.Generic;
using System.ComponentModel;

namespace Baci.ArcGIS._GeoAnalyticsServerTools._AnalyzePatterns
{
    /// <summary>
    /// <para>Forest-based Classification and Regression</para>
    /// <para>Creates models and generates predictions using an adaptation of Leo Breiman's random forest algorithm, which is a supervised machine learning method. Predictions can be performed for both categorical variables (classification) and continuous variables (regression). Explanatory variables can take the form of fields in the attribute table of the training features. In addition to validation of model performance based on the training data, predictions can be made to features.</para>
    /// <para>使用 Leo Breiman 的随机森林算法（一种监督式机器学习方法）的改编来创建模型并生成预测。可以对分类变量（分类）和连续变量（回归）执行预测。解释变量可以采用训练要素属性表中的字段形式。除了基于训练数据验证模型性能外，还可以对特征进行预测。</para>
    /// </summary>    
    [DisplayName("Forest-based Classification and Regression")]
    public class Forest : AbstractGPProcess
    {
        /// <summary>
        /// 无参构造
        /// </summary>
        public Forest()
        {

        }

        /// <summary>
        /// 有参构造
        /// </summary>
        /// <param name="_prediction_type">
        /// <para>Prediction Type</para>
        /// <para><xdoc>
        ///   <para>Specifies the operation mode of the tool. The tool can be run to train a model to only assess performance, predict features, or create a prediction surface.</para>
        ///   <bulletList>
        ///     <bullet_item>Train only—A model will be trained, but no predictions will be generated. Use this option to assess the accuracy of your model before generating predictions. This option will output model diagnostics in the messages window and a chart of variable importance. This is the default</bullet_item><para/>
        ///     <bullet_item>Train and Predict—Predictions or classifications will be generated for features. Explanatory variables must be provided for both the training features and the features to be predicted. The output of this option will be a feature class, model diagnostics in the messages window, and an optional table of variable importance.</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// <para><xdoc>
        ///   <para>指定工具的操作模式。可以运行该工具来训练模型，使其仅评估性能、预测特征或创建预测表面。</para>
        ///   <bulletList>
        ///     <bullet_item>仅训练—将训练模型，但不会生成预测。在生成预测之前，使用此选项可以评估模型的准确性。此选项将在消息窗口中输出模型诊断和具有可变重要性的图表。这是默认设置</bullet_item><para/>
        ///     <bullet_item>训练和预测—将为要素生成预测或分类。必须为训练特征和要预测的特征提供解释变量。此选项的输出将是一个要素类、消息窗口中的模型诊断以及一个具有可变重要性的可选表。</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// </param>
        /// <param name="_in_features">
        /// <para>Input Training Features</para>
        /// <para>The layercontaining the Variable to Predict parameter and the explanatory training variables fields.</para>
        /// <para>包含要预测的变量参数和解释性训练变量字段的图层。</para>
        /// </param>
        /// <param name="_output_trained_name">
        /// <para>Output Features Name</para>
        /// <para>The output feature layer name.</para>
        /// <para>输出要素图层名称。</para>
        /// </param>
        /// <param name="_variable_predict">
        /// <para>Variable to Predict</para>
        /// <para>The variable from the Input Training Features parameter containing the values to be used to train the model. This field contains known (training) values of the variable that will be used to predict at unknown locations.</para>
        /// <para>输入训练特征参数中的变量，包含用于训练模型的值。此字段包含变量的已知（训练）值，这些值将用于在未知位置进行预测。</para>
        /// </param>
        public Forest(_prediction_type_value _prediction_type, object _in_features, object _output_trained_name, object _variable_predict)
        {
            this._prediction_type = _prediction_type;
            this._in_features = _in_features;
            this._output_trained_name = _output_trained_name;
            this._variable_predict = _variable_predict;
        }
        public override string ToolboxName => "GeoAnalytics Server Tools";

        public override string ToolName => "Forest-based Classification and Regression";

        public override string CallName => "geoanalytics.Forest";

        public override List<string> AcceptEnvironments => ["extent", "outputCoordinateSystem", "workspace"];

        public override object[] ParameterInfo => [_prediction_type.GetGPValue(), _in_features, _output_trained_name, _variable_predict, _treat_variable_as_categorical.GetGPValue(), _explanatory_variables, _create_variable_importance_table.GetGPValue(), _features_to_predict, _explanatory_variable_matching, _number_of_trees, _minimum_leaf_size, _maximum_tree_depth, _sample_size, _random_variables, _percentage_for_validation, _data_store.GetGPValue(), _output_trained, _variable_of_importance, _output_predicted];

        /// <summary>
        /// <para>Prediction Type</para>
        /// <para><xdoc>
        ///   <para>Specifies the operation mode of the tool. The tool can be run to train a model to only assess performance, predict features, or create a prediction surface.</para>
        ///   <bulletList>
        ///     <bullet_item>Train only—A model will be trained, but no predictions will be generated. Use this option to assess the accuracy of your model before generating predictions. This option will output model diagnostics in the messages window and a chart of variable importance. This is the default</bullet_item><para/>
        ///     <bullet_item>Train and Predict—Predictions or classifications will be generated for features. Explanatory variables must be provided for both the training features and the features to be predicted. The output of this option will be a feature class, model diagnostics in the messages window, and an optional table of variable importance.</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// <para><xdoc>
        ///   <para>指定工具的操作模式。可以运行该工具来训练模型，使其仅评估性能、预测特征或创建预测表面。</para>
        ///   <bulletList>
        ///     <bullet_item>仅训练—将训练模型，但不会生成预测。在生成预测之前，使用此选项可以评估模型的准确性。此选项将在消息窗口中输出模型诊断和具有可变重要性的图表。这是默认设置</bullet_item><para/>
        ///     <bullet_item>训练和预测—将为要素生成预测或分类。必须为训练特征和要预测的特征提供解释变量。此选项的输出将是一个要素类、消息窗口中的模型诊断以及一个具有可变重要性的可选表。</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// <para></para>
        /// </summary>
        [DisplayName("Prediction Type")]
        [Description("")]
        [Option(OptionTypeEnum.Must)]
        public _prediction_type_value _prediction_type { get; set; }

        public enum _prediction_type_value
        {
            /// <summary>
            /// <para>Train only</para>
            /// <para>Train only—A model will be trained, but no predictions will be generated. Use this option to assess the accuracy of your model before generating predictions. This option will output model diagnostics in the messages window and a chart of variable importance. This is the default</para>
            /// <para>仅训练—将训练模型，但不会生成预测。在生成预测之前，使用此选项可以评估模型的准确性。此选项将在消息窗口中输出模型诊断和具有可变重要性的图表。这是默认设置</para>
            /// </summary>
            [Description("Train only")]
            [GPEnumValue("TRAIN")]
            _TRAIN,

            /// <summary>
            /// <para>Train and Predict</para>
            /// <para>Train and Predict—Predictions or classifications will be generated for features. Explanatory variables must be provided for both the training features and the features to be predicted. The output of this option will be a feature class, model diagnostics in the messages window, and an optional table of variable importance.</para>
            /// <para>训练和预测—将为要素生成预测或分类。必须为训练特征和要预测的特征提供解释变量。此选项的输出将是一个要素类、消息窗口中的模型诊断以及一个具有可变重要性的可选表。</para>
            /// </summary>
            [Description("Train and Predict")]
            [GPEnumValue("TRAIN_AND_PREDICT")]
            _TRAIN_AND_PREDICT,

        }

        /// <summary>
        /// <para>Input Training Features</para>
        /// <para>The layercontaining the Variable to Predict parameter and the explanatory training variables fields.</para>
        /// <para>包含要预测的变量参数和解释性训练变量字段的图层。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Input Training Features")]
        [Description("")]
        [Option(OptionTypeEnum.Must)]
        public object _in_features { get; set; }


        /// <summary>
        /// <para>Output Features Name</para>
        /// <para>The output feature layer name.</para>
        /// <para>输出要素图层名称。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Output Features Name")]
        [Description("")]
        [Option(OptionTypeEnum.Must)]
        public object _output_trained_name { get; set; }


        /// <summary>
        /// <para>Variable to Predict</para>
        /// <para>The variable from the Input Training Features parameter containing the values to be used to train the model. This field contains known (training) values of the variable that will be used to predict at unknown locations.</para>
        /// <para>输入训练特征参数中的变量，包含用于训练模型的值。此字段包含变量的已知（训练）值，这些值将用于在未知位置进行预测。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Variable to Predict")]
        [Description("")]
        [Option(OptionTypeEnum.Must)]
        public object _variable_predict { get; set; }


        /// <summary>
        /// <para>Treat Variable as Categorical</para>
        /// <para><xdoc>
        ///   <para>Specifies whether Variable to Predict is a categorical variable.</para>
        ///   <bulletList>
        ///     <bullet_item>Checked—Variable to Predict is a categorical variable and the tool will perform classification.</bullet_item><para/>
        ///     <bullet_item>Unchecked—Variable to Predict is continuous and the tool will perform regression. This is the default.</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// <para><xdoc>
        ///   <para>指定要预测的变量是否为分类变量。</para>
        ///   <bulletList>
        ///     <bullet_item>选中 - 要预测的变量是分类变量，工具将执行分类。</bullet_item><para/>
        ///     <bullet_item>未选中 - 要预测的变量是连续的，工具将执行回归。这是默认设置。</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// <para></para>
        /// </summary>
        [DisplayName("Treat Variable as Categorical")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public _treat_variable_as_categorical_value? _treat_variable_as_categorical { get; set; } = null;

        public enum _treat_variable_as_categorical_value
        {
            /// <summary>
            /// <para>CATEGORICAL</para>
            /// <para></para>
            /// <para></para>
            /// </summary>
            [Description("CATEGORICAL")]
            [GPEnumValue("true")]
            _true,

            /// <summary>
            /// <para>NUMERIC</para>
            /// <para></para>
            /// <para></para>
            /// </summary>
            [Description("NUMERIC")]
            [GPEnumValue("false")]
            _false,

        }

        /// <summary>
        /// <para>Explanatory Variables</para>
        /// <para>A list of fields representing the explanatory variables that help predict the value or category of Variable to Predict. Check the Categorical check box for any variables that represent classes or categories (such as land cover or presence or absence).</para>
        /// <para>表示解释变量的字段列表，这些变量有助于预测要预测的变量的值或类别。选中表示类或类别（例如土地覆被或存在或不存在）的任何变量的分类复选框。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Explanatory Variables")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public object _explanatory_variables { get; set; } = null;


        /// <summary>
        /// <para>Create Variable Importance Table</para>
        /// <para><xdoc>
        ///   <para>Specifies whether the output table will contain information describing the importance of each explanatory variable used in the model.</para>
        ///   <bulletList>
        ///     <bullet_item>Checked—The output table will contain information for each explanatory variable.</bullet_item><para/>
        ///     <bullet_item>Unchecked—The output table will not contain information for each explanatory variable. This is the default.</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// <para><xdoc>
        ///   <para>指定输出表是否包含描述模型中使用的每个解释变量的重要性的信息。</para>
        ///   <bulletList>
        ///     <bullet_item>选中 - 输出表将包含每个解释变量的信息。</bullet_item><para/>
        ///     <bullet_item>未选中 - 输出表将不包含每个解释变量的信息。这是默认设置。</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// <para></para>
        /// </summary>
        [DisplayName("Create Variable Importance Table")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public _create_variable_importance_table_value? _create_variable_importance_table { get; set; } = null;

        public enum _create_variable_importance_table_value
        {
            /// <summary>
            /// <para>CREATE_TABLE</para>
            /// <para></para>
            /// <para></para>
            /// </summary>
            [Description("CREATE_TABLE")]
            [GPEnumValue("true")]
            _true,

            /// <summary>
            /// <para>NO_TABLE</para>
            /// <para></para>
            /// <para></para>
            /// </summary>
            [Description("NO_TABLE")]
            [GPEnumValue("false")]
            _false,

        }

        /// <summary>
        /// <para>Input Prediction Features</para>
        /// <para>A feature layer representing locations where predictions will be made. This feature layer must also contain any explanatory variables provided as fields that correspond to those used from the training data.</para>
        /// <para>表示将进行预测的位置的要素图层。此要素图层还必须包含作为字段提供的任何解释变量，这些变量与训练数据中使用的变量相对应。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Input Prediction Features")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public object _features_to_predict { get; set; } = null;


        /// <summary>
        /// <para>Match Explanatory Variables</para>
        /// <para>A list of Explanatory Variables specified from Input Training Features on the right and their corresponding fields from Input Prediction Features on the left.</para>
        /// <para>右侧的输入训练要素中指定的解释变量列表，左侧的输入预测要素中指定的相应字段。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Match Explanatory Variables")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public object _explanatory_variable_matching { get; set; } = null;


        /// <summary>
        /// <para>Number of Trees</para>
        /// <para>The number of trees to create in the forest model. More trees will generally result in more accurate model prediction, but the model will take longer to calculate. The default number of trees is 100.</para>
        /// <para>要在森林模型中创建的树数。更多的树通常会导致更准确的模型预测，但模型需要更长的时间来计算。默认树数为 100。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Number of Trees")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long _number_of_trees { get; set; } = 100;


        /// <summary>
        /// <para>Minimum Leaf Size</para>
        /// <para>The minimum number of observations required to keep a leaf (that is, the terminal node on a tree without further splits). The default minimum for regression is 5, and the default for classification is 1. For very large data, increasing these numbers will decrease the run time of the tool.</para>
        /// <para>保留叶（即树上的终端节点，没有进一步拆分）所需的最小观测值数。回归的默认最小值为 5，分类的默认值为 1。对于非常大的数据，增加这些数字将减少工具的运行时间。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Minimum Leaf Size")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long? _minimum_leaf_size { get; set; } = null;


        /// <summary>
        /// <para>Maximum Tree Depth</para>
        /// <para>The maximum number of splits that will be made down a tree. Using a large maximum depth, more splits will be created, which may increase the chances of overfitting the model. The default is data driven and depends on the number of trees created and the number of variables included.</para>
        /// <para>将沿着树进行的最大拆分数。使用较大的最大深度，将创建更多的分割，这可能会增加模型过度拟合的机会。默认值是数据驱动的，取决于创建的树数和包含的变量数。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Maximum Tree Depth")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long? _maximum_tree_depth { get; set; } = null;


        /// <summary>
        /// <para>Data Available per Tree (%)</para>
        /// <para><xdoc>
        ///   <para>The percentage of Input Training Features used for each decision tree. The default is 100 percent of the data. Samples for each tree are taken randomly from two-thirds of the data specified.</para>
        ///   <para>Each decision tree in the forest is created using a random sample or subset (approximately two-thirds) of the training data available. Using a lower percentage of the input data for each decision tree increases the speed of the tool for very large datasets.</para>
        /// </xdoc></para>
        /// <para><xdoc>
        ///   <para>用于每个决策树的输入训练特征的百分比。默认值为 100% 的数据。每棵树的样本是从指定数据的三分之二中随机抽取的。</para>
        ///   <para>森林中的每个决策树都是使用可用训练数据的随机样本或子集（大约三分之二）创建的。对每个决策树使用较低百分比的输入数据可提高工具处理超大型数据集的速度。</para>
        /// </xdoc></para>
        /// <para></para>
        /// </summary>
        [DisplayName("Data Available per Tree (%)")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long _sample_size { get; set; } = 100;


        /// <summary>
        /// <para>Number of Randomly Sampled Variables</para>
        /// <para><xdoc>
        ///   <para>The number of explanatory variables used to create each decision tree.</para>
        ///   <para>Each decision tree in the forest is created using a random subset of the explanatory variables specified. Increasing the number of variables used in each decision tree will increase the chances of overfitting your model, particularly if there is one or more dominant variables. A common practice is to use the square root of the total number of explanatory variables if Variable to Predict is numeric, or divide the total number of explanatory variables by 3 if Variable to Predict is categorical.</para>
        /// </xdoc></para>
        /// <para><xdoc>
        ///   <para>用于创建每个决策树的解释变量的数量。</para>
        ///   <para>森林中的每个决策树都是使用指定解释变量的随机子集创建的。增加每个决策树中使用的变量数量将增加模型过度拟合的几率，尤其是在存在一个或多个主导变量的情况下。通常的做法是，如果要预测的变量是数值，则使用解释变量总数的平方根，如果要预测的变量是分类的，则使用解释变量总数除以 3。</para>
        /// </xdoc></para>
        /// <para></para>
        /// </summary>
        [DisplayName("Number of Randomly Sampled Variables")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long? _random_variables { get; set; } = null;


        /// <summary>
        /// <para>Training Data Excluded for Validation (%)</para>
        /// <para>The percentage (between 10 percent and 50 percent) of Input Training Features to reserve as the test dataset for validation. The model will be trained without this random subset of data, and the observed values for those features will be compared to the predicted values. The default is 10 percent.</para>
        /// <para>要保留为验证测试数据集的输入训练要素的百分比（介于 10% 和 50% 之间）。模型将在没有此随机数据子集的情况下进行训练，并将这些特征的观测值与预测值进行比较。默认值为 10%。</para>
        /// <para></para>
        /// </summary>
        [DisplayName("Training Data Excluded for Validation (%)")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public long _percentage_for_validation { get; set; } = 10;


        /// <summary>
        /// <para>Data Store</para>
        /// <para><xdoc>
        ///   <para>Specifies the ArcGIS Data Store where the output will be saved. The default is Spatiotemporal big data store. All results stored in a spatiotemporal big data store will be stored in WGS84. Results stored in a relational data store will maintain their coordinate system.</para>
        ///   <bulletList>
        ///     <bullet_item>Spatiotemporal big data store—Output will be stored in a spatiotemporal big data store. This is the default.</bullet_item><para/>
        ///     <bullet_item>Relational data store—Output will be stored in a relational data store.</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// <para><xdoc>
        ///   <para>指定将保存输出的 ArcGIS Data Store。默认值为 Spatiotemporal 大数据存储。存储在时空大数据存储中的所有结果都将存储在 WGS84 中。存储在关系数据存储中的结果将保留其坐标系。</para>
        ///   <bulletList>
        ///     <bullet_item>时空大数据存储 - 输出将存储在时空大数据存储中。这是默认设置。</bullet_item><para/>
        ///     <bullet_item>关系数据存储 - 输出将存储在关系数据存储中。</bullet_item><para/>
        ///   </bulletList>
        /// </xdoc></para>
        /// <para></para>
        /// </summary>
        [DisplayName("Data Store")]
        [Description("")]
        [Option(OptionTypeEnum.optional)]
        public _data_store_value _data_store { get; set; } = _data_store_value._SPATIOTEMPORAL_DATA_STORE;

        public enum _data_store_value
        {
            /// <summary>
            /// <para>Relational data store</para>
            /// <para>Relational data store—Output will be stored in a relational data store.</para>
            /// <para>关系数据存储 - 输出将存储在关系数据存储中。</para>
            /// </summary>
            [Description("Relational data store")]
            [GPEnumValue("RELATIONAL_DATA_STORE")]
            _RELATIONAL_DATA_STORE,

            /// <summary>
            /// <para>Spatiotemporal big data store</para>
            /// <para>Spatiotemporal big data store—Output will be stored in a spatiotemporal big data store. This is the default.</para>
            /// <para>时空大数据存储 - 输出将存储在时空大数据存储中。这是默认设置。</para>
            /// </summary>
            [Description("Spatiotemporal big data store")]
            [GPEnumValue("SPATIOTEMPORAL_DATA_STORE")]
            _SPATIOTEMPORAL_DATA_STORE,

        }

        /// <summary>
        /// <para>Output Trained Features</para>
        /// <para></para>
        /// <para></para>
        /// <para></para>
        /// </summary>
        [DisplayName("Output Trained Features")]
        [Description("")]
        [Option(OptionTypeEnum.derived)]
        public object _output_trained { get; set; }


        /// <summary>
        /// <para>Variable of Importance Table</para>
        /// <para></para>
        /// <para></para>
        /// <para></para>
        /// </summary>
        [DisplayName("Variable of Importance Table")]
        [Description("")]
        [Option(OptionTypeEnum.derived)]
        public object _variable_of_importance { get; set; }


        /// <summary>
        /// <para>Output Predicted Features</para>
        /// <para></para>
        /// <para></para>
        /// <para></para>
        /// </summary>
        [DisplayName("Output Predicted Features")]
        [Description("")]
        [Option(OptionTypeEnum.derived)]
        public object _output_predicted { get; set; }


        public Forest SetEnv(object extent = null, object outputCoordinateSystem = null, object workspace = null)
        {
            base.SetEnv(extent: extent, outputCoordinateSystem: outputCoordinateSystem, workspace: workspace);
            return this;
        }

    }

}